import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
	private static ServerSocket server_sock;
	private static Socket client_sock;
	private static BufferedReader buffered_reader;
	private static String msg;
	
	public static void main(String[] args) {
		 
        try {
            server_sock = new ServerSocket(8080);  //Server socket
 
        } catch (IOException e) {
            System.out.println("Could not listen on port: 8080");
        }
 
        System.out.println("Server started. Listening to the port 8080");
 
        while (true) {
            try {
                client_sock = server_sock.accept();   //accept the client connection
                buffered_reader = new BufferedReader(new InputStreamReader(client_sock.getInputStream())); // reader for getting input from the socket 
          
		msg = buffered_reader.readLine();//get the client message 
                System.out.println(msg);
                client_sock.getOutputStream().print(msg);
                
                input_stream.close();
                client_sock.close();
            } catch (IOException ex) {
                System.out.println("IO exception in client socket");
            }
        }
 
    }
}
